/*
 * Radio.cc
 *
 *  Created on: Oct 16, 2014
 *      Author: andy
 */

#include <cstdlib>
#include <iostream>
#include <ctime>

#include "Radio.h"

Radio::Radio(int f) {
	// Initialize to random frequency
	setFrequency(f < 0 ? time(NULL) : f);
}

void Radio::setFrequency(int f) {
	// Reinitialize station parameters for the new "frequency"
	srand(f);

#ifdef DEBUG_FIXED_RADIAL
	// Defining DEBUG_FIXED_RADIAL in the build makes the station radial lock to 0.
	radial = 0;
	valid = true;
#else
	radial = rand() % 360;      // Actual radial
	valid = (rand() % 16) != 0; // One out of 15 runs (avg) has the signal be invalid
#endif

	// Generate random identifier (i.e., three random upper case letters)
	for(int i = 0; i < 3; ++i) {
		ident[i] = (rand() % 26) + 'A';
	}
	ident[3] = 0; // Null termination
}


std::ostream &operator<<(std::ostream &out, const Radio &r) {
	out << "Station: "
		<< "radial=" << r.radial
		<< ", valid=" << r.valid
		<< ", ident: " << r.ident;

	return out;
}

